﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using sgsBase;

namespace gaClear
{
	class Log
	{
		public static void LogData(string data, string refid)
		{
			//string nightFile = "am";
			//if (DateTime.Now.Hour > 8)
			//    nightFile = "wk";

			data = data.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
			string outfile = "\\lf_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + refid + ".xml";
			string path = ApplicationHelper.PhysicalPath;
			string filepath = path + "logs\\" + DateTime.Now.ToString("yyyyMMdd");

			if (!Directory.Exists(filepath))
				Directory.CreateDirectory(filepath);
		
			FileStream fout = new FileStream(filepath + outfile, FileMode.OpenOrCreate, FileAccess.Write);
			StreamWriter sw = new StreamWriter(fout);

			sw.Write(data + "\n");
			sw.Close();

			fout.Close();
		}

		public static void LogData(string data)
		{
			string nightFile = "am";
			if (DateTime.Now.Hour > 8)
				nightFile = "wk";

			string outfile = "logfile_" + DateTime.Now.Year + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + nightFile + ".txt";
			string path = ApplicationHelper.PhysicalPath;
			string filepath = path + "logs\\" + DateTime.Now.ToString("yyyyMMdd");

			if (!Directory.Exists(filepath))
				Directory.CreateDirectory(filepath);
		
			FileStream fout = new FileStream(path + "logs\\" + outfile, FileMode.Append, FileAccess.Write);
			StreamWriter sw = new StreamWriter(fout);

			sw.Write("<Message>\n" + DateTime.Now.ToString() + " " + data + "\n</Message>\n");
			sw.Close();

			fout.Close();
		}
	}
}
